package com.md.infrastructure.client;

import com.google.common.collect.Maps;
import com.md.api.OpenSystemApi;
import com.md.request.BatchIdRequest;
import com.md.response.AppInfoResponse;
import com.md.util.CollectionUtil;
import com.md.util.ObjectUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.function.Function;

/**
 * @author 刘骄阳
 * 2024-12-08 0:47
 */
@Component
@RequiredArgsConstructor
public class SystemClient {
  private final OpenSystemApi openSystemApi;

  public Map<Long, AppInfoResponse> getAppInfoResponseByIds(final List<Long> ids) {
    if (ObjectUtil.isEmpty(ids)) {
      return Maps.newHashMap();
    }
    BatchIdRequest request = new BatchIdRequest();
    request.setIds(ids);
    return CollectionUtil.toMap(openSystemApi.openQueryIdsList(request).getData(),
      AppInfoResponse::getId, Function.identity());
  }

}
